﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iShoppingDTO;
using iShoppingBUS;

namespace iShopping.Manager
{
    public partial class QuanLyComment : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            GiaoDienDTO giaoDienDto = GiaoDienBUS.SelectGiaoDienMa("Theme001");
            if (giaoDienDto != null)
            {
                this.Theme = giaoDienDto.TenTheme;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            String maSanPham = Request.QueryString["MSP"].ToString();
            Session.Add("MaSanPham", maSanPham);
            String maTaiKhoan = Request.QueryString["MTK"].ToString();
            Session.Add("MaTaiKhoan", maTaiKhoan);
            if (Request.QueryString["MCM"] != null)
            {
                string macomment = Request.QueryString["MCM"].ToString();
                CommentBUS.DeleteComment(macomment.ToString());
                Response.Redirect("QuanLyComment.aspx?MSP=" + maSanPham + "&MTK=" + maTaiKhoan);
            }
        }

        protected void BtnComment_Click(object sender, EventArgs e)
        {
            string noidung = TbComment.Text;
            DateTime date = DateTime.Now;
            long ticks = date.Ticks;
            CommentDTO comment = new CommentDTO();
            comment.MaCommment = ticks;
            comment.NoiDungComment = noidung;
            comment.NgayComment = DateTime.Now;
            comment.MaTaiKhoan = Session["MaTaiKhoan"].ToString();
            comment.MaSanPham = Session["MaSanPham"].ToString();
            CommentBUS.InsertComment(comment);
            TbComment.Text = "";
        }
    }
}
